home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / libkcal / calendarresources.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-01-15  |  20.7 KB  |  697 lines

  1. /*
  2.     This file is part of libkcal.
  3.  
  4.     Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
  5.     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
  6.  
  7.     This library is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU Library General Public
  9.     License as published by the Free Software Foundation; either
  10.     version 2 of the License, or (at your option) any later version.
  11.  
  12.     This library is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.     Library General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU Library General Public License
  18.     along with this library; see the file COPYING.LIB.  If not, write to
  19.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20.     Boston, MA 02110-1301, USA.
  21. */
  22. /**
  23.    @file calendarresources.h
  24.    Provides a Calendar composed of several Calendar Resources.
  25.  
  26.    @author Cornelius Schumacher
  27.    @author Reinhold Kainhofer
  28.  */
  29. #ifndef KCAL_CALENDARRESOURCES_H
  30. #define KCAL_CALENDARRESOURCES_H
  31.  
  32. #include <qintdict.h>
  33. #include <qmap.h>
  34.  
  35. #include "calendar.h"
  36. #include "resourcecalendar.h"
  37.  
  38. #include "libkcal_export.h"
  39.  
  40. #include <kresources/manager.h>
  41.  
  42. class QWidget;
  43.  
  44. /**
  45.    @namespace KCal
  46.    Namespace KCal is for global classes, objects and/or functions in libkcal.
  47. */
  48. namespace KCal {
  49.  
  50. class CalFormat;
  51.  
  52. /**
  53.    @class CalendarResources
  54.  
  55.    This class provides a Calendar which is composed of other Calendars
  56.    known as "Resources".
  57.  
  58.    Examples of Calendar Resources are:
  59.      - Calendars stored as local ICS formatted files
  60.      - a set of incidences (one-per-file) within a local directory
  61.      - birthdays and anniversaries contained in an addressbook
  62.  
  63. */
  64. class LIBKCAL_EXPORT CalendarResources :
  65.       public Calendar,
  66.       public KRES::ManagerObserver<ResourceCalendar>
  67. {
  68.   Q_OBJECT
  69.   public:
  70.     /**
  71.        @class DestinationPolicy
  72.     */
  73.     class DestinationPolicy
  74.     {
  75.       public:
  76.         DestinationPolicy( CalendarResourceManager *manager,
  77.                               QWidget *parent = 0  ) :
  78.           mManager( manager ), mParent( parent ) {}
  79.  
  80.         virtual ResourceCalendar *destination( Incidence *incidence ) = 0;
  81.         virtual QWidget *parent() { return mParent; }
  82.         virtual void setParent( QWidget *newparent ) { mParent = newparent; }
  83.  
  84.       protected:
  85.         CalendarResourceManager *resourceManager()
  86.          { return mManager; }
  87.  
  88.       private:
  89.         CalendarResourceManager *mManager;
  90.         QWidget *mParent;
  91.     };
  92.  
  93.     /**
  94.        @class StandardDestinationPolicy
  95.     */
  96.     class StandardDestinationPolicy : public DestinationPolicy
  97.     {
  98.       public:
  99.         StandardDestinationPolicy( CalendarResourceManager *manager,
  100.                               QWidget *parent = 0  ) :
  101.           DestinationPolicy( manager, parent ) {}
  102.  
  103.         ResourceCalendar *destination( Incidence *incidence );
  104.  
  105.       private:
  106.         class Private;
  107.         Private *d;
  108.     };
  109.  
  110.     /**
  111.        @class AskDestinationPolicy
  112.     */
  113.     class AskDestinationPolicy : public DestinationPolicy
  114.     {
  115.       public:
  116.         AskDestinationPolicy( CalendarResourceManager *manager,
  117.                               QWidget *parent = 0 ) :
  118.           DestinationPolicy( manager, parent ) {}
  119.  
  120.         ResourceCalendar *destination( Incidence *incidence );
  121.  
  122.       private:
  123.         class Private;
  124.         Private *d;
  125.     };
  126.  
  127.     /**
  128.        @class Ticket
  129.     */
  130.     class Ticket
  131.     {
  132.         friend class CalendarResources;
  133.       public:
  134.         ResourceCalendar *resource() const
  135.           { return mResource; }
  136.  
  137.       private:
  138.         Ticket( ResourceCalendar *r ) : mResource( r ) {}
  139.  
  140.         ResourceCalendar *mResource;
  141.  
  142.         class Private;
  143.         Private *d;
  144.     };
  145.  
  146.     /**
  147.        Construct CalendarResource object using a Time Zone and a Family name.
  148.  
  149.        @param timeZoneId is a string containing a Time Zone ID, which is
  150.        assumed to be valid. The Time Zone Id is used to set the time zone
  151.        for viewing Incidence dates.\n
  152.        On some systems, /usr/share/zoneinfo/zone.tab may be available for
  153.        reference.\n
  154.        @e Example: "Europe/Berlin"
  155.  
  156.        @warning
  157.        Do Not pass an empty timeZoneId string as this may cause unintended
  158.        consequences when storing Incidences into the Calendar.
  159.  
  160.        @param family is any QString representing a unique name.
  161.     */
  162.     CalendarResources(
  163.       const QString &timeZoneId,
  164.       const QString &family = QString::fromLatin1( "calendar" ) );
  165.  
  166.     /**
  167.        Destructor
  168.     */
  169.     ~CalendarResources();
  170.  
  171.     /**
  172.        Loads all Incidences from the Resources.  The Resources must be added
  173.        first using either readConfig(KConfig *config), which adds the system
  174.        Resources, or manually using resourceAdded(ResourceCalendar *resource).
  175.     */
  176.     void load();
  177.  
  178.     /**
  179.      * Reloads all incidences from all resources.
  180.      * @par tz The timezone to set.
  181.      * @return success or failure
  182.      */
  183.     bool reload( const QString &tz );
  184.  
  185.     /**
  186.        Clear out the current Calendar, freeing all used memory etc.
  187.     */
  188.     void close();
  189.  
  190.     /**
  191.        Save this Calendar.
  192.        If the save is successfull, the Ticket is deleted.  Otherwise, the
  193.        caller must release the Ticket with releaseSaveTicket() to abandon
  194.        the save operation or call save() to try the save again.
  195.  
  196.        @param ticket is a pointer to the Ticket object.
  197.        @param incidence is a pointer to the Incidence object.
  198.        If incidence is null, save the entire Calendar (all Resources)
  199.        else only the specified Incidence is saved.
  200.  
  201.        @return true if the save was successful; false otherwise.
  202.     */
  203.     virtual bool save( Ticket *ticket, Incidence *incidence = 0 );
  204.  
  205.     /**
  206.        Sync changes in memory to persistant storage.
  207.     */
  208.     void save();
  209.  
  210.     /**
  211.        Determine if the Calendar is currently being saved.
  212.  
  213.        @return true if the Calendar is currently being saved; false otherwise.
  214.     */
  215.     bool isSaving();
  216.  
  217.     /**
  218.        Get the CalendarResourceManager used by this calendar.
  219.  
  220.        @return a pointer to the CalendarResourceManage.
  221.     */
  222.     CalendarResourceManager *resourceManager() const
  223.       { return mManager; }
  224.  
  225.     /**
  226.        Get the Resource associated with a specified Incidence.
  227.  
  228.        @param incidence is a pointer to an Incidence whose Resource
  229.        is to be located.
  230.  
  231.        @return a pointer to the Resource containing the Incidence.
  232.     */
  233.     ResourceCalendar *resource( Incidence *incidence );
  234.  
  235.     /**
  236.        Read the Resources settings from a config file.
  237.  
  238.        @param config The KConfig object which points to the config file.
  239.        If no object is given (null pointer) the standard config file is used.
  240.  
  241.        @note Call this method <em>before</em> load().
  242.     */
  243.     void readConfig( KConfig *config = 0 );
  244.  
  245.     /**
  246.        Set the destination policy such that Incidences are always added
  247.        to the standard Resource.
  248.     */
  249.     void setStandardDestinationPolicy();
  250.  
  251.     /**
  252.        Set the destination policy such that Incidences are added to a
  253.        Resource which is queried.
  254.     */
  255.     void setAskDestinationPolicy();
  256.     
  257.     /** 
  258.        Returns the current parent for new dialogs. This is a bad hack, but we need
  259.        to properly set the parent for the resource selection dialog. Otherwise
  260.        the dialog will not be modal to the editor dialog in korganizer and 
  261.        the user can still work in the editor dialog (and thus crash korganizer).
  262.        Afterwards we need to reset it (to avoid pointers to widgets that are 
  263.        already deleted) so we also need the accessor
  264.     */
  265.     QWidget *dialogParentWidget();
  266.     /** 
  267.        Set the widget parent for new dialogs. This is a bad hack, but we need
  268.        to properly set the parent for the resource selection dialog. Otherwise
  269.        the dialog will not be modal to the editor dialog in korganizer and 
  270.        the user can still work in the editor dialog (and thus crash korganizer).
  271.     */
  272.     void setDialogParentWidget( QWidget *parent );
  273.  
  274.     /**
  275.        Request ticket for saving the Calendar.  If a ticket is returned the
  276.        Calendar is locked for write access until save() or releaseSaveTicket()
  277.        is called.
  278.  
  279.        @param resource is a pointer to the ResourceCalendar object.
  280.  
  281.        @return a pointer to a Ticket object indicating that the Calendar
  282.        is locked for write access; otherwise a null pointer.
  283.     */
  284.     Ticket *requestSaveTicket( ResourceCalendar *resource );
  285.  
  286.     /**
  287.        Release the save Ticket. The Calendar is unlocked without saving.
  288.  
  289.        @param ticket is a pointer to a Ticket object.
  290.     */
  291.     virtual void releaseSaveTicket( Ticket *ticket );
  292.  
  293.     /**
  294.        Add a Resource to the Calendar.
  295.        This method must be public, because in-process added Resources
  296.        do not emit the corresponding signal, so this methodd has to be
  297.        called manually!
  298.  
  299.        @param resource is a pointer to the ResourceCalendar to add.
  300.     */
  301.     void resourceAdded( ResourceCalendar *resource );
  302.  
  303. // Incidence Specific Methods //
  304.  
  305.     /**
  306.        Insert an Incidence into the Calendar.
  307.  
  308.        @param incidence is a pointer to the Incidence to insert.
  309.  
  310.        @return true if the Incidence was successfully inserted; false otherwise.
  311.     */
  312.     bool addIncidence( Incidence *incidence );
  313.  
  314.     /**
  315.        Insert an Incidence into a Calendar Resource.
  316.  
  317.        @param incidence is a pointer to the Incidence to insert.
  318.        @param resource is a pointer to the ResourceCalendar to be added to.
  319.  
  320.        @return true if the Incidence was successfully inserted; false otherwise.
  321.     */
  322.     bool addIncidence( Incidence *incidence, ResourceCalendar *resource );
  323.  
  324.     /**
  325.        Flag that a change to a Calendar Incidence is starting.
  326.  
  327.        @param incidence is a pointer to the Incidence that will be changing.
  328.     */
  329.     bool beginChange( Incidence *incidence );
  330.  
  331.     /**
  332.        Flag that a change to a Calendar Incidence has completed.
  333.  
  334.        @param incidence is a pointer to the Incidence that was changed.
  335.     */
  336.     bool endChange( Incidence *incidence );
  337.  
  338. // Event Specific Methods //
  339.  
  340.     /**
  341.        Insert an Event into the Calendar.
  342.  
  343.        @param event is a pointer to the Event to insert.
  344.  
  345.        @return true if the Event was successfully inserted; false otherwise.
  346.  
  347.        @note In most cases use
  348.        addIncidence( Incidence *incidence ) instead.
  349.     */
  350.     bool addEvent( Event *event );
  351.  
  352.     /**
  353.        Insert an Event into a Calendar Resource.
  354.  
  355.        @param event is a pointer to the Event to insert.
  356.        @param resource is a pointer to the ResourceCalendar to be added to.
  357.  
  358.        @return true if the Event was successfully inserted; false otherwise.
  359.  
  360.        @note In most cases use
  361.        addIncidence( Incidence *incidence, ResourceCalendar *resource ) instead.
  362.     */
  363.     bool addEvent( Event *event, ResourceCalendar *resource );
  364.  
  365.     /**
  366.        Remove an Event from the Calendar.
  367.  
  368.        @param event is a pointer to the Event to remove.
  369.  
  370.        @return true if the Event was successfully removed; false otherwise.
  371.  
  372.        @note In most cases use
  373.        deleteIncidence( Incidence *incidence) instead.
  374.     */
  375.     bool deleteEvent( Event *event );
  376.  
  377.     /**
  378.        Return a sorted, unfiltered list of all Events.
  379.  
  380.        @param sortField specifies the EventSortField.
  381.        @param sortDirection specifies the SortDirection.
  382.  
  383.        @return the list of all unfiltered Events sorted as specified.
  384.     */
  385.     Event::List rawEvents(
  386.       EventSortField sortField = EventSortUnsorted,
  387.       SortDirection sortDirection = SortDirectionAscending );
  388.  
  389.     /**
  390.        Return an unfiltered list of all Events which occur on the given
  391.        timestamp.
  392.  
  393.        @param qdt request unfiltered Event list for this QDateTime only.
  394.  
  395.        @return the list of unfiltered Events occurring on the specified
  396.        timestamp.
  397.     */
  398.     Event::List rawEventsForDate( const QDateTime &qdt );
  399.  
  400.     /**
  401.        Return an unfiltered list of all Events occurring within a date range.
  402.  
  403.        @param start is the starting date.
  404.        @param end is the ending date.
  405.        @param inclusive if true only Events which are completely included
  406.        within the date range are returned.
  407.  
  408.        @return the list of unfiltered Events occurring within the specified
  409.        date range.
  410.     */
  411.     Event::List rawEvents( const QDate &start, const QDate &end,
  412.                            bool inclusive = false );
  413.  
  414.     /**
  415.        Return a sorted, unfiltered list of all Events which occur on the given
  416.        date.  The Events are sorted according to @a sortField and
  417.        @a sortDirection.
  418.  
  419.        @param date request unfiltered Event list for this QDate only.
  420.        @param sortField specifies the EventSortField.
  421.        @param sortDirection specifies the SortDirection.
  422.  
  423.        @return the list of sorted, unfiltered Events occurring on @a date.
  424.     */
  425.     Event::List rawEventsForDate(
  426.       const QDate &date,
  427.       EventSortField sortField = EventSortUnsorted,
  428.       SortDirection sortDirection = SortDirectionAscending );
  429.  
  430.     /**
  431.        Returns the Event associated with the given unique identifier.
  432.  
  433.        @param uid is a unique identifier string.
  434.  
  435.        @return a pointer to the Event.
  436.        A null pointer is returned if no such Event exists.
  437.     */
  438.     Event *event( const QString &uid );
  439.  
  440. // Todo Specific Methods //
  441.  
  442.     /**
  443.        Insert a Todo into a Calendar Resource.
  444.  
  445.        @param todo is a pointer to the Todo to insert.
  446.  
  447.        @return true if the Todo was successfully inserted; false otherwise.
  448.  
  449.        @note In most cases use
  450.        addIncidence( Incidence *incidence ) instead.
  451.     */
  452.     bool addTodo( Todo *todo );
  453.  
  454.     /**
  455.        Insert an Todo into a Calendar Resource.
  456.  
  457.        @param todo is a pointer to the Todo to insert.
  458.        @param resource is a pointer to the ResourceCalendar to be added to.
  459.  
  460.        @return true if the Todo was successfully inserted; false otherwise.
  461.  
  462.        @note In most cases use
  463.        addIncidence( Incidence *incidence, ResourceCalendar *resource ) instead.
  464.     */
  465.     bool addTodo( Todo *todo, ResourceCalendar *resource );
  466.  
  467.     /**
  468.        Remove an Todo from the Calendar.
  469.  
  470.        @param todo is a pointer to the Todo to remove.
  471.  
  472.        @return true if the Todo was successfully removed; false otherwise.
  473.  
  474.        @note In most cases use
  475.        deleteIncidence( Incidence *incidence ) instead.
  476.     */
  477.     bool deleteTodo( Todo *todo );
  478.  
  479.     /**
  480.        Return a sorted, unfiltered list of all Todos for this Calendar.
  481.  
  482.        @param sortField specifies the TodoSortField.
  483.        @param sortDirection specifies the SortDirection.
  484.  
  485.        @return the list of all unfiltered Todos sorted as specified.
  486.     */
  487.     Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted,
  488.                          SortDirection sortDirection = SortDirectionAscending );
  489.  
  490.     /**
  491.        Return an unfiltered list of all Todos which are due on the specified
  492.        date.
  493.  
  494.        @param date request unfiltered Todos due on this QDate.
  495.  
  496.        @return the list of unfiltered Todos due on the specified date.
  497.     */
  498.     Todo::List rawTodosForDate( const QDate &date );
  499.  
  500.     /**
  501.        Returns the Todo associated with the given unique identifier.
  502.  
  503.        @param uid is a unique identifier string.
  504.  
  505.        @return a pointer to the Todo.
  506.        A null pointer is returned if no such Todo exists.
  507.     */
  508.     Todo *todo( const QString &uid );
  509.  
  510. // Journal Specific Methods //
  511.  
  512.     /**
  513.        Insert a Journal into the Calendar.
  514.  
  515.        @param journal is a pointer to the Journal to insert.
  516.  
  517.        @return true if the Journal was successfully inserted; false otherwise.
  518.  
  519.        @note In most cases use
  520.        addIncidence( Incidence *incidence ) instead.
  521.     */
  522.     bool addJournal( Journal *journal );
  523.  
  524.     /**
  525.        Insert a Journal into a Calendar Resource.
  526.  
  527.        @param journal is a pointer to the Journal to insert.
  528.        @param resource is a pointer to the ResourceCalendar to be added to.
  529.  
  530.        @return true if the Journal was successfully inserted; false otherwise.
  531.  
  532.        @note In most cases use
  533.        addIncidence( Incidence *incidence, ResourceCalendar *resource ) instead.
  534.     */
  535.     bool addJournal( Journal *journal, ResourceCalendar *resource );
  536.  
  537.     /**
  538.        Remove a Journal from the Calendar.
  539.  
  540.        @param journal is a pointer to the Journal to remove.
  541.  
  542.        @return true if the Journal was successfully removed; false otherwise.
  543.  
  544.        @note In most cases use
  545.        deleteIncidence( Incidence *incidence ) instead.
  546.     */
  547.     bool deleteJournal( Journal *journal );
  548.  
  549.     /**
  550.        Return a sorted, unfiltered list of all Journals for this Calendar.
  551.  
  552.        @param sortField specifies the JournalSortField.
  553.        @param sortDirection specifies the SortDirection.
  554.  
  555.        @return the list of all unfiltered Journals sorted as specified.
  556.     */
  557.     Journal::List rawJournals(
  558.       JournalSortField sortField = JournalSortUnsorted,
  559.       SortDirection sortDirection = SortDirectionAscending );
  560.  
  561.     /**
  562.        Return an unfiltered list of all Journals for on the specifed date.
  563.  
  564.        @param date request unfiltered Journals for this QDate only.
  565.  
  566.        @return the list of unfiltered Journals for the specified date.
  567.     */
  568.     Journal::List rawJournalsForDate( const QDate &date );
  569.  
  570.     /**
  571.        Returns the Journal associated with the given unique identifier.
  572.  
  573.        @param uid is a unique identifier string.
  574.  
  575.        @return a pointer to the Journal.
  576.        A null pointer is returned if no such Journal exists.
  577.     */
  578.     Journal *journal( const QString &uid );
  579.  
  580. // Alarm Specific Methods //
  581.  
  582.     /**
  583.        Return a list of Alarms within a time range for this Calendar.
  584.  
  585.        @param from is the starting timestamp.
  586.        @param to is the ending timestamp.
  587.  
  588.        @return the list of Alarms for the for the specified time range.
  589.     */
  590.     Alarm::List alarms( const QDateTime &from, const QDateTime &to );
  591.  
  592.     /**
  593.        Return a list of Alarms that occur before the specified timestamp.
  594.  
  595.        @param to is the ending timestamp.
  596.  
  597.        @return the list of Alarms occurring before the specified QDateTime.
  598.     */
  599.     Alarm::List alarmsTo( const QDateTime &to );
  600.  
  601.     /**
  602.      * Set the viewing time zone, which requires that all resources are saved,
  603.      * and then reloaded such that the event times are re-interpreted in the new
  604.      * timezone. Note that the absolute times of events do not change with this.
  605.      * If you want to change the times of the contents of the resources, use
  606.      * setTimeZoneId
  607.      */
  608.     void setTimeZoneIdViewOnly( const QString& tz );
  609.  
  610.   signals:
  611.     /**
  612.        Signal that the Resource has been modified.
  613.     */
  614.     void signalResourceModified( ResourceCalendar *resource );
  615.  
  616.     /**
  617.        Signal that an Incidence has been inserted to the Resource.
  618.     */
  619.     void signalResourceAdded( ResourceCalendar *resource );
  620.  
  621.     /**
  622.        Signal that an Incidence has been removed from the Resource.
  623.     */
  624.     void signalResourceDeleted( ResourceCalendar *resource );
  625.  
  626.     /**
  627.        Signal an error message.
  628.     */
  629.     void signalErrorMessage( const QString &err );
  630.  
  631.   protected:
  632.     void connectResource( ResourceCalendar *resource );
  633.     void resourceModified( ResourceCalendar *resource );
  634.     void resourceDeleted( ResourceCalendar *resource );
  635.  
  636.     /**
  637.        Let CalendarResource subclasses set the Time Zone ID.
  638.  
  639.        First parameter is a string containing a Time Zone ID, which is
  640.        assumed to be valid. On some systems, /usr/share/zoneinfo/zone.tab
  641.        may be available for reference.\n
  642.        @e Example: "Europe/Berlin"
  643.  
  644.        @warning
  645.        Do Not pass an empty timeZoneId string as this may cause unintended
  646.        consequences when storing Incidences into the Calendar.
  647.     */
  648.     virtual void doSetTimeZoneId( const QString &timeZoneId );
  649.  
  650.     /**
  651.        Increment the number of times this Resource has been changed by 1.
  652.  
  653.        @param resource is a pointer to the ResourceCalendar to be counted.
  654.  
  655.        @return the new number of times this Resource has been changed.
  656.     */
  657.     int incrementChangeCount( ResourceCalendar *resource );
  658.  
  659.     /**
  660.        Decrement the number of times this Resource has been changed by 1.
  661.  
  662.        @param resource is a pointer to the ResourceCalendar to be counted.
  663.  
  664.        @return the new number of times this Resource has been changed.
  665.     */
  666.     int decrementChangeCount( ResourceCalendar *resource );
  667.  
  668.   protected slots:
  669.     void slotLoadError( ResourceCalendar *resource, const QString &err );
  670.     void slotSaveError( ResourceCalendar *resource, const QString &err );
  671.  
  672.   private:
  673.     /**
  674.        Initialize the Resource object with starting values.
  675.     */
  676.     void init( const QString &family );
  677.  
  678.     bool mOpen;
  679.  
  680.     KRES::Manager<ResourceCalendar>* mManager;
  681.     QMap <Incidence*, ResourceCalendar*> mResourceMap;
  682.  
  683.     DestinationPolicy *mDestinationPolicy;
  684.     StandardDestinationPolicy *mStandardPolicy;
  685.     AskDestinationPolicy *mAskPolicy;
  686.  
  687.     QMap<ResourceCalendar *, Ticket *> mTickets;
  688.     QMap<ResourceCalendar *, int> mChangeCounts;
  689.  
  690.     class Private;
  691.     Private *d;
  692. };
  693.  
  694. }
  695.  
  696. #endif
  697.